import { axios } from '@/utils/request'
import { mimeMap, resolveBlob } from '@/utils/download'

/**
 * 用户列表
 */
export function getUserList(params) {
  return axios({
    url: `/admin/app-user-info/pageList?current=${params.current}&size=${params.size}`,
    method: 'post',
    data: params
  })
}

/**
 * 用户类型统计数量
 */
export function getUserStatistics() {
  return axios({
    url: `/admin/app-user-info/getAppUserInfoStatistics`,
    method: 'get'
  })
}


/**
 * 获取用户信息
 */
export function getUserDetail(id) {
  return axios({
    url: `/admin/app-user-info/getByUserInfoId/${id}`,
    method: 'get'
  })
}

/**
 * 添加或者修改用户资料
 */
export function editUserInfo(params) {
  return axios({
    url: `/admin/app-user-info/addOrUpdateById`,
    method: 'post',
    data: params
  })
}

/**
 * 获取用户单位列表
 */
export function getUserCompanies(params) {
  return axios({
    url: `/system/companies/user/list`,
    method: 'get',
    params
  })
}

/**
 * 用户列表导出
 */
export function userExportExcel(params) {
  return axios({
    url: `/admin/app-user-info/exportExcel`,
    method: 'post',
    responseType: 'blob',
    timeout: 0,
    data: params
  })
}

/**
 * 用户导入下载模板
 */
export function userExportemplate() {
  return axios({
      url: `/admin/app-user-info/exportTemplate`,
      method: 'get',
      responseType: 'blob',
      timeout: 0
  }).then(res => {
      resolveBlob(res, mimeMap.xlsx)
  })
}

/**
 * 用户批量导入
 */
export function userImportExcel(data) {
  return axios({
    url: `/admin/app-user-info/importExcel`,
    method: 'post',
    responseType: 'blob',
    timeout: 0,
    data
  })
}



/**
 * 新增单位
 */
export function addUserCompanies(params) {
  return axios({
    url: `/system/companies/add`,
    method: 'post',
    data: params
  })
}

/**
 * 编辑单位
 */
export function editUserCompanies(params) {
  return axios({
    url: `/system/companies/edit`,
    method: 'post',
    data: params
  })
}

/**
 * 删除单位
 */
export function deleteUserCompanies(id) {
  return axios({
    url: `/system/companies/del?id=${id}`,
    method: 'get'
  })
}

/**
 * 设置默认单位
 */
export function setDefaultIdentity(params) {
  return axios({
    url: `/admin/app-user-info/setDefaultIdentity`,
    method: 'post',
    data: params
  })
}

//全选用户列表
export function checkedAllUser(params) {
  return axios({
      url: `/admin/app-user-info/allIds`,
      method: 'post',
      data: params
  })
}
